package com.hskn.hss.module.kfkcarlocation.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.kfkcarlocation.entity.KfkCarLocation;
import com.hskn.hss.module.kfkcarlocation.mapper.KfkCarLocationMapper;
import com.hskn.hss.module.kfkcarlocation.service.IKfkCarLocationService;
import com.hskn.hss.module.statistics.vo.KfkCarLocationListRes;
import com.hskn.hss.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hskn
 * @since 2021-05-25
 */
@Service
public class KfkCarLocationServiceImpl extends ServiceImpl<KfkCarLocationMapper, KfkCarLocation> implements IKfkCarLocationService {

    @Autowired
    KfkCarLocationMapper kfkCarLocationMapper;

    @Override
    public void insert(KfkCarLocation kfkCarLocation) throws HssException {
        kfkCarLocationMapper.insert(kfkCarLocation);
    }

    @Override
    public JSONObject getDcylqxQbsjList(JSONObject params) throws HssException {

        JSONObject json = new JSONObject();
        Long page = StringUtils.isEmpty(params.getLong("page")) ? 1 : params.getLong("page");
        Long size = StringUtils.isEmpty(params.getLong("size")) ? 10 : params.getLong("size");
        Page<KfkCarLocationListRes> pageCase = new Page<>(page, size, true);
        IPage<KfkCarLocationListRes> iPage = kfkCarLocationMapper.getDcylqxQbsjList(pageCase, params);
        json.put("total", iPage.getTotal());
        json.put("size", iPage.getSize());
        json.put("pages", iPage.getPages());
        json.put("current", iPage.getCurrent());
        json.put("list", iPage.getRecords());
        return json;
    }

    @Override
    public JSONObject getHybbAchzChart(JSONObject params) throws HssException {
        JSONObject json = new JSONObject();
        List<KfkCarLocationListRes> casesList = kfkCarLocationMapper.getHybbAchzChart(params);
        json.put("list", casesList);
        return json;
    }

    @Override
    public JSONObject getHybbSjzsChart(JSONObject params) throws HssException {
        JSONObject json = new JSONObject();
        List<KfkCarLocationListRes> casesList = kfkCarLocationMapper.getHybbSjzsChart(params);
        json.put("list", casesList);
        return json;
    }

    @Override
    public JSONObject getHybbYhtjList(JSONObject params) throws HssException {
        JSONObject json = new JSONObject();
        Long page = StringUtils.isEmpty(params.getLong("page")) ? 1 : params.getLong("page");
        Long size = StringUtils.isEmpty(params.getLong("size")) ? 10 : params.getLong("size");
        Page<KfkCarLocationListRes> pageCase = new Page<>(page, size, true);
        IPage<KfkCarLocationListRes> iPage = kfkCarLocationMapper.getHybbYhtjList(pageCase, params);
        json.put("total", iPage.getTotal());
        json.put("size", iPage.getSize());
        json.put("pages", iPage.getPages());
        json.put("current", iPage.getCurrent());
        json.put("list", iPage.getRecords());
        return json;
    }

    @Override
    public JSONObject getHybbMrtjList(JSONObject params) throws HssException {
        JSONObject json = new JSONObject();
        Long page = StringUtils.isEmpty(params.getLong("page")) ? 1 : params.getLong("page");
        Long size = StringUtils.isEmpty(params.getLong("size")) ? 10 : params.getLong("size");
        Page<KfkCarLocationListRes> pageCase = new Page<>(page, size, true);
        IPage<KfkCarLocationListRes> iPage = kfkCarLocationMapper.getHybbMrtjList(pageCase, params);
        json.put("total", iPage.getTotal());
        json.put("size", iPage.getSize());
        json.put("pages", iPage.getPages());
        json.put("current", iPage.getCurrent());
        json.put("list", iPage.getRecords());
        return json;
    }
}
